package br.gerenciadorAudio.DB;

import java.util.ArrayList;
import java.util.List;

import br.gerenciadorAudio.Model.ProfileSchedule;

import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQuery;

public class SqLiteCursor extends SQLiteCursor {

	public SqLiteCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
			String editTable, SQLiteQuery query) {
		super(db, driver, editTable, query);
		// TODO Auto-generated constructor stub
	}
	
	public List<ProfileSchedule> LoadSchedule(Cursor c)
	{
		
		List<ProfileSchedule> profileSchedules = new ArrayList<ProfileSchedule>();
		
		if (c.moveToFirst()) 
		{
			
			int idId = c.getColumnIndex(ProfileSchedule.Colunas.Id);
			int idPerfil = c.getColumnIndex(ProfileSchedule.Colunas.IdPerfil);
			int idDateOfBegin = c.getColumnIndex(ProfileSchedule.Colunas.DateOfBegin);
			int idDateOfEnd = c.getColumnIndex(ProfileSchedule.Colunas.DateOfEnd);
			int idFriday = c.getColumnIndex(ProfileSchedule.Colunas.Friday);
			int idMonday = c.getColumnIndex(ProfileSchedule.Colunas.Monday);
			int idSaturday = c.getColumnIndex(ProfileSchedule.Colunas.Saturday);
			int idSunday = c.getColumnIndex(ProfileSchedule.Colunas.Sunday);
			int idThursday = c.getColumnIndex(ProfileSchedule.Colunas.Thursday);
			int idTuesday = c.getColumnIndex(ProfileSchedule.Colunas.Tuesday);
			int idWednesday = c.getColumnIndex(ProfileSchedule.Colunas.Wednesday);
			int idActive = c.getColumnIndex(ProfileSchedule.Colunas.Active);

			
			do {
				ProfileSchedule profileSchedule = new ProfileSchedule();
				
				profileSchedule.Id = c.getInt(idId);
				profileSchedule.IdPerfil = c.getInt(idPerfil);
				profileSchedule.DateOfBegin = c.getString(idDateOfBegin);
				profileSchedule.DateOfEnd = c.getString(idDateOfEnd);
				profileSchedule.Monday = c.getInt(idMonday) == 1;
				profileSchedule.Thursday = c.getInt(idThursday) == 1;
				profileSchedule.Tuesday = c.getInt(idTuesday) == 1;
				profileSchedule.Wednesday = c.getInt(idWednesday) == 1;
				profileSchedule.Friday = c.getInt(idFriday) == 1;
				profileSchedule.Saturday = c.getInt(idSaturday) == 1;
				profileSchedule.Sunday = c.getInt(idSunday) == 1;
				profileSchedule.Active = c.getInt(idActive) == 1;
				
				profileSchedules.add(profileSchedule);
				
			} while (c.moveToNext());
		
		}
		
		return profileSchedules;
	}

}
